home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / GEM_XACC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-31  |  3.3 KB  |  159 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    GEM eXtended Accessory protocol (communications protocol)        *
  4.  *    Released by Atari Corp, modified by Ken Hollis                    *
  5.  *                                                                    *
  6.  *    Copyright (c) Atari Corp, Bitgate Software, and Clever Bits 1994*
  7.  *    All rights reserved.                                            *
  8.  *                                                                    *
  9.  *    This is the standard protocol for sending text, image, and        *
  10.  *    metafile information to accessories.  Use at your own risk,        *
  11.  *    since we've not tested them fully.                                *
  12.  *                                                                    *
  13.  ********************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <tos.h>
  19. #include "winlib.h"
  20.  
  21. LOCAL int appl_id, menu_id, msg[8], ToAccApp = 0;
  22. LOCAL long tmp_count = 0;
  23.  
  24. #define    XNAME "WinLIB Test 0.64\0XDSC\01xWinLIB Custom Test\0\0"
  25.  
  26. LOCAL char *XACCName;
  27.  
  28. GLOBAL void XACC_Send(int sendto, int msg0, int msg3, char *msg4, int msg6, int msg7)
  29. {
  30.     int     msg[8];
  31.   
  32.     msg[0]             = msg0;
  33.     msg[1]             = Ap_ID;
  34.     msg[2]             = 0;
  35.     msg[3]             = msg3;
  36.     *(char**)&msg[4] = msg4;
  37.     msg[6]             = msg6;
  38.     msg[7]             = msg7;
  39.  
  40.     appl_write(sendto, 16, msg);
  41. }
  42.  
  43. GLOBAL void XACC_Send_Id(int sendto)
  44. {
  45.     XACC_Send(sendto, ACC_ID, 0x0103, XACCName, menu_id, -1);
  46. }
  47.  
  48. GLOBAL void XACC_Send_Ack(int sendto, int answer)
  49. {
  50.     XACC_Send(sendto, ACC_ACK, answer, NULL, -1, -1);
  51. }
  52.  
  53. GLOBAL void XACC_Send_AccClose(void)
  54. {
  55.     if (!_app && !(_GemParBlk.global[0] >= 0x0400 && _GemParBlk.global[1] == -1))
  56.         XACC_SendId(ToAccApp);
  57. }
  58.  
  59. GLOBAL void XACC_SendStartup(void)
  60. {
  61.     int     next, type, id;
  62.     char    name[10], *buf;
  63.     long    *MiNTCOOKIE;
  64.  
  65.     get_cookie('MiNT', &MiNTCOOKIE);  
  66.  
  67.     if (AES_VERSION >= 0x0400 && MiNTCOOKIE != NULL) {
  68.         buf = Mxalloc(sizeof(XNAME), 0x0022);
  69.  
  70.         if (buf != NULL)
  71.             memcpy(buf, XACCName, sizeof(XNAME));
  72.  
  73.         XACCName = buf;
  74.         next = 0;
  75.  
  76.         while (appl_search(next, name, &type, &id)) {
  77.             if (type & 0x06)
  78.                 XACC_SendId(id);
  79.             next = 1;
  80.         }
  81.     } else {
  82.         if (!_app)
  83.             XACC_SendAccClose();
  84.     }
  85. }
  86.  
  87. GLOBAL void getfile(char **input, long *length)
  88. {
  89.     char    path[220];
  90.     char    file[20], *s;
  91.     int     ret, ex, fh;
  92.     
  93.     *input = NULL;
  94.     *length = 0;
  95.     path[0] = '\0';
  96.     file[0] = '\0';
  97.  
  98.     ret = fsel_input(path, file, &ex);
  99.  
  100.     if (ret == 0 || ex == 0)
  101.         return;
  102.     
  103.     s = strrchr(path, '\\');
  104.  
  105.     if (s == NULL)
  106.         return;
  107.     
  108.     strcpy(s+1, file);
  109.     fh = (int) Fopen(path, FO_READ);
  110.  
  111.     if (fh < 0)
  112.         return;
  113.     
  114.     *length = Fseek(0L, fh, SEEK_END);
  115.  
  116.     Fseek(0L, fh, SEEK_SET);
  117.  
  118.     *input = malloc(*length + 10L);
  119.  
  120.     if (*input == NULL) {
  121.         Fclose(fh);
  122.         return;
  123.     }
  124.     
  125.     memset(*input, '\0', *length + 10L);
  126.     Fread(fh, *length, *input);
  127.  
  128.     Fclose(fh);
  129. }
  130.  
  131. GLOBAL int XACC_Wait(int *msg, int wait)
  132. {
  133.     int        event, dummy;
  134.   
  135.     msg[0] = 0;
  136.     event = evnt_multi(MU_MESAG|MU_TIMER, 0, 0, 0,
  137.                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  138.                         msg, wait, 0, &dummy, &dummy,
  139.                         &dummy, &dummy, &dummy, &dummy);
  140.     if (event & MU_MESAG) {
  141.         if (msg[0] == 0x0500 && msg[3] == 1)
  142.             return TRUE;
  143.         if (msg[0] == AC_OPEN)
  144.             return FALSE;
  145.         if (msg[0] == AC_CLOSE)
  146.             return FALSE;
  147.         if (msg[0] == ACC_TEXT)
  148.             return FALSE;
  149.         if (msg[0] == ACC_IMG)
  150.             return FALSE;
  151.         if (msg[0] == ACC_META)
  152.             return FALSE;
  153.     }
  154.     if (!(event & MU_MESAG))
  155.         tmp_count++;
  156.  
  157.     return FALSE;
  158. }
  159.